package com.scs.application.core.model;

import com.baomidou.mybatisplus.annotation.TableField;
import com.scs.application.core.utils.StringUtils;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
 * ${DESCRIPTION}
 *
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class TreeEntity extends DataEntity {


    private Long sort;

    @TableField
    private String parentId;

    @TableField
    private String parentIds;

    /**
     * 获取当前层级。从0开始
     * parent_ids == ,0,  代表1 。
     * @return
     */
    public int getLevel(){
        if(StringUtils.isBlank(parentIds)){
            return 0;
        }
        int length = StringUtils.split(parentIds, ",").length;
        if(length <= 1){
            return 0;
        }
        return length - 1;
    }
}

